﻿using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005D8 RID: 1496
	public class WorkspaceCtrl : MonoBehaviour
	{
		// Token: 0x170004B8 RID: 1208
		// (get) Token: 0x06002632 RID: 9778 RVA: 0x000E0240 File Offset: 0x000DE440
		// (set) Token: 0x06002633 RID: 9779 RVA: 0x000E0248 File Offset: 0x000DE448
		private Button[] buttons { get; set; }

		// Token: 0x06002634 RID: 9780 RVA: 0x000E0254 File Offset: 0x000DE454
		private void OnClickClose()
		{
			this.studioScene.OnClickDraw(1);
		}

		// Token: 0x06002635 RID: 9781 RVA: 0x000E0264 File Offset: 0x000DE464
		private void OnClickRemove()
		{
			this.treeNodeCtrl.RemoveNode();
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
		}

		// Token: 0x06002636 RID: 9782 RVA: 0x000E02A4 File Offset: 0x000DE4A4
		private void OnClickParent()
		{
			this.treeNodeCtrl.SetParent();
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
		}

		// Token: 0x06002637 RID: 9783 RVA: 0x000E02E4 File Offset: 0x000DE4E4
		public void OnClickDelete()
		{
			this.treeNodeCtrl.DeleteNode();
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
			Singleton<UndoRedoManager>.Instance.Clear();
		}

		// Token: 0x06002638 RID: 9784 RVA: 0x000E0330 File Offset: 0x000DE530
		private void OnClickCopy()
		{
			this.treeNodeCtrl.CopyChangeAmount();
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
		}

		// Token: 0x06002639 RID: 9785 RVA: 0x000E0370 File Offset: 0x000DE570
		private void OnClickDuplicate()
		{
			Singleton<Studio>.Instance.Duplicate();
		}

		// Token: 0x0600263A RID: 9786 RVA: 0x000E037C File Offset: 0x000DE57C
		private void OnClickFolder()
		{
			Singleton<Studio>.Instance.AddFolder();
		}

		// Token: 0x0600263B RID: 9787 RVA: 0x000E0388 File Offset: 0x000DE588
		public void UpdateUI()
		{
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
		}

		// Token: 0x0600263C RID: 9788 RVA: 0x000E03BC File Offset: 0x000DE5BC
		public void OnParentage(TreeNodeObject _parent, TreeNodeObject _child)
		{
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
		}

		// Token: 0x0600263D RID: 9789 RVA: 0x000E03F0 File Offset: 0x000DE5F0
		public void OnDeleteNode(TreeNodeObject _node)
		{
			for (int i = 0; i < this.buttons.Length; i++)
			{
				this.buttons[i].interactable = false;
			}
		}

		// Token: 0x0600263E RID: 9790 RVA: 0x000E0424 File Offset: 0x000DE624
		public void OnSelectSingle(TreeNodeObject _node)
		{
			this.buttonParent.interactable = false;
			this.buttonRemove.interactable = _node.isParent;
			this.buttonDelete.interactable = _node.enableDelete;
			this.buttonCopy.interactable = false;
			this.buttonDuplicate.interactable = _node.enableCopy;
		}

		// Token: 0x0600263F RID: 9791 RVA: 0x000E047C File Offset: 0x000DE67C
		public void OnSelectMultiple()
		{
			TreeNodeObject[] selectNodes = this.treeNodeCtrl.selectNodes;
			if (selectNodes.IsNullOrEmpty<TreeNodeObject>())
			{
				return;
			}
			this.buttonParent.interactable = selectNodes.Any((TreeNodeObject v) => v.enableChangeParent);
			this.buttonRemove.interactable = selectNodes.Any((TreeNodeObject v) => v.isParent);
			this.buttonDelete.interactable = selectNodes.Any((TreeNodeObject v) => v.enableDelete);
			Selectable selectable = this.buttonCopy;
			bool interactable;
			if (selectNodes[0].enableCopy)
			{
				interactable = (selectNodes.Count((TreeNodeObject v) => v.enableCopy) > 1);
			}
			else
			{
				interactable = false;
			}
			selectable.interactable = interactable;
			this.buttonDuplicate.interactable = selectNodes.Any((TreeNodeObject v) => v.enableCopy);
		}

		// Token: 0x06002640 RID: 9792 RVA: 0x000E059C File Offset: 0x000DE79C
		private void Awake()
		{
			this.textBar.font.material.mainTexture.filterMode = FilterMode.Point;
			this.buttonClose.onClick.AddListener(new UnityAction(this.OnClickClose));
			this.buttonRemove.onClick.AddListener(new UnityAction(this.OnClickRemove));
			this.buttonParent.onClick.AddListener(new UnityAction(this.OnClickParent));
			this.buttonDelete.onClick.AddListener(new UnityAction(this.OnClickDelete));
			this.buttonCopy.onClick.AddListener(new UnityAction(this.OnClickCopy));
			this.buttonDuplicate.onClick.AddListener(new UnityAction(this.OnClickDuplicate));
			this.buttonFolder.onClick.AddListener(new UnityAction(this.OnClickFolder));
			TreeNodeCtrl treeNodeCtrl = this.treeNodeCtrl;
			treeNodeCtrl.onParentage = (Action<TreeNodeObject, TreeNodeObject>)Delegate.Combine(treeNodeCtrl.onParentage, new Action<TreeNodeObject, TreeNodeObject>(this.OnParentage));
			TreeNodeCtrl treeNodeCtrl2 = this.treeNodeCtrl;
			treeNodeCtrl2.onDelete = (Action<TreeNodeObject>)Delegate.Combine(treeNodeCtrl2.onDelete, new Action<TreeNodeObject>(this.OnDeleteNode));
			TreeNodeCtrl treeNodeCtrl3 = this.treeNodeCtrl;
			treeNodeCtrl3.onSelect = (Action<TreeNodeObject>)Delegate.Combine(treeNodeCtrl3.onSelect, new Action<TreeNodeObject>(this.OnSelectSingle));
			TreeNodeCtrl treeNodeCtrl4 = this.treeNodeCtrl;
			treeNodeCtrl4.onSelectMultiple = (Action)Delegate.Combine(treeNodeCtrl4.onSelectMultiple, new Action(this.OnSelectMultiple));
			this.buttons = new Button[]
			{
				this.buttonRemove,
				this.buttonParent,
				this.buttonDelete,
				this.buttonCopy,
				this.buttonDuplicate
			};
		}

		// Token: 0x04002653 RID: 9811
		[SerializeField]
		private Button buttonClose;

		// Token: 0x04002654 RID: 9812
		[SerializeField]
		private Button buttonRemove;

		// Token: 0x04002655 RID: 9813
		[SerializeField]
		private Button buttonParent;

		// Token: 0x04002656 RID: 9814
		[SerializeField]
		private TreeNodeCtrl treeNodeCtrl;

		// Token: 0x04002657 RID: 9815
		[SerializeField]
		private Button buttonDelete;

		// Token: 0x04002658 RID: 9816
		[SerializeField]
		private Button buttonCopy;

		// Token: 0x04002659 RID: 9817
		[SerializeField]
		private Button buttonDuplicate;

		// Token: 0x0400265A RID: 9818
		[SerializeField]
		private Button buttonFolder;

		// Token: 0x0400265B RID: 9819
		[SerializeField]
		private StudioScene studioScene;

		// Token: 0x0400265C RID: 9820
		[SerializeField]
		private Text textBar;
	}
}
